package com.atbeijing.bigdata.spark.core.rdd.operator.transform

import org.apache.spark.{SparkConf, SparkContext}

object Spark19_Oper_Transform {

    def main(args: Array[String]): Unit = {

        val conf = new SparkConf().setMaster("local[*]").setAppName("TransformOperator")
        val sc = new SparkContext(conf)

        // TODO 算子 - 转换 - KV - aggregateByKey (6 / 10)
        val rdd = sc.makeRDD(
            List(
                ("a", 1), ("a", 2), ("b", 3),
                ("a", 4), ("b", 5), ("b", 6)
            ),2
        )
        rdd.groupByKey()
        rdd.reduceByKey(_+_)
        rdd.aggregateByKey(0)(_+_, _+_)
        rdd.foldByKey(0)(_+_)
        rdd.combineByKey(
            num=>num,
            (x:Int, y) => x + y,
            (x:Int, y:Int) => x + y
        )

        sc.stop()

    }
    class User {

    }
}
